window.addEventListener('load', function() {
    var parmas = location.search.substr(1);
    var arr = parmas.split('=');
    console.log(location.search);
    console.log(arr.length);
    for (var i = 0; i < arr.length; i++) {
        console.log(arr[i]);
    }

    var loginBox = document.querySelector('.loginBox');
    document.querySelector('#login_icon').onclick = function() {
        loginBox.style.display = 'block';
    }
    document.querySelector('.icon-close').onclick = function() {
        loginBox.style.display = 'none';
    }
    var search = document.querySelector('.search');
    var text = search.children[0];
    search.children[1].onclick = function() {
        if (text.textContent == '') {
            alert('您还没有输入任何内容！');
        } else {
            alert('YES');
        }
    };
    text.onfocus = function() {
        console.log('获得了焦点');
        if (text.value == '搜索') {
            text.value = '';
        }
    }
    text.onblur = function() {
        console.log('失去了焦点');
        if (text.value == '') {
            text.value = '搜索';
        }
    }
    var login = document.querySelectorAll('#login');
    console.log(login);
    login[0].onfocus = function() {
        console.log('得到用户名焦点');
        if (login[0].value == '用户名') {
            login[0].value = '';
        }
    }
    login[0].onblur = function() {
        console.log('失去用户名焦点');
        if (login[0].value == '') {
            login[0].value = '用户名';
        }
    }
    login[1].onfocus = function() {
        if (login[1].value == '********') {
            login[1].value = '';
        }
    }
    login[1].onblur = function() {
            if (login[1].value == '') {
                login[1].value = '********';
            }
        }
        /*登录名 */
    var uname = document.querySelector('.signed');
    if (arr[0] == 'username') {
        uname.innerHTML = arr[1];
        uname.previousElementSibling.style.display = 'none';
    } else {
        uname.innerHTML = '';
        uname.previousElementSibling.style.display = 'block';
    }

    /*模态图制作 */
    var movearea = document.querySelector('#movearea');
    movearea.addEventListener('mousedown', function(e) {
        var x = e.PageX - loginBox.offsetLeft;
        var y = e.PageY - loginBox.offsetTop;
        console.log(x);
        console.log(y);
        movearea.addEventListener('mousemove', mousemove);

        function mousemove(e) {
            loginBox.style.left = e.PageX - x + 'px';
            loginBox.style.top = e.PageY - y + 'px';
        }
        movearea.addEventListener('mouseup', function() {
            movearea.removeEventListener('mousemove', mousemove);
        });
    })
    var btn = this.document.querySelector('.category').children;
    for (var i = 0; i < btn.length; i++) {
        btn[i].addEventListener('click', function() {
            location.href = 'classify.html';
        })
    }

})